<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.lp.cfg.ProConfig"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/oss/iot/common/variable.jsp"%>
<%@ include file="/WEB-INF/oss/iot/common/variable_js.jsp"%>
<%@ include file="/WEB-INF/oss/iot/common/resource_lib.jsp"%>
<style type="text/css">
	.index_theLeft ul {
	    width: 100%;
	    padding: 0px;
	    margin: 0px;
	    overflow: auto;
	}
	.index_theLeft li {
	    list-style: none;
	    position: relative;
	     padding: 15px 0 15px 20px;
	    border-bottom: 1px solid #f9f9f9;
	    cursor: pointer;
	}
	
	.index_theLeft li.active , .index_theLeft li:HOVER{
		background: #f9f9f9;
	}
	
	.index_theLeft li span,.index_theLeft li h5{
		text-align: center;
		color: #333;
	}
	.mapContainer{
		height: 550px;width:100%;padding-left:170px;
	}
	.dashboard-menu{
		border-top:1px solid #ecf0f5;
	}
	.app-container{
		background:  #f2f2f2;width: 100%;border-top:1px solid #ecf0f5;
	}
	
	.box-white {
	    width: 97%;
	    min-width: 897px;
	    padding-bottom: 0;
	    margin: 0 auto;
	}
	.box {
	    padding: 10px;
	    padding-top:1px;
	    border-left: 1px solid #d2d6de;
	    border-right: 1px solid #d2d6de;
	    border-bottom: 1px solid #d2d6de;
	}
	.box {
	    border: 0!important;
	    box-shadow: 0 0 2px 1px rgba(13,5,9,.08)!important;
	}
	.box {
	    position: relative;
	    border-radius: 3px;
	    background: #fff;
	    border-top: 3px solid #d2d6de;
	    margin-bottom: 20px;
	    width: 100%;
	    box-shadow: 0 1px 1px rgba(0,0,0,.1);
	}

.sceneList-info{
	padding-top: 10px;
	padding-left: 10px;
}
.generateStyle{
	position: absolute;
	top: 18px;
	right: 10px;
	cursor: pointer;
}
.webui-popover{
	z-index: 19991015;
}
</style>
</head>
<body>
	<div>
		<!--  下方部位  -->
		<div style="background: #ecf0f5;">
			<div class="mapContainer" style="padding-left: 0;" >
				<div class="app-container">
					<div class="container-layout sceneList-info">
						<div class="box join-device-box">
							
							<div class="search-container jui-search_table" data-options="submit:'#searchbtns',
															table:'#init-table'">
									<span class="titleName">设备类型管理</span> 
									<span>设备类型名称：</span> 
									<input type-name="name" placeholder="设备类型名称模糊查询"  class="input input-self" />
									<input type-name="scene_id" class="scene_id" type="hidden" />
									
									<button onclick="add();" class="button ml-20 bg-iot float-right"><span class="icon-plus"></span> 新增类型</button>  
									<button id="searchbtns" class="button ml-20 bg-iot float-right"><span class="icon-search"></span> 查询</button>
							</div>
							
							 <div style="margin-top:10px;">
								<div id="init-table" type-option="table"  config-option="url:'/page/deviceTemplateInfo',
											param:{ user_id :'${user.id}'},
											columns:[
												{'name':'序号','type':'seq','value':'seq','width':'4%'}, 
												{'name':'设备模板名称','value':'name','width':'10%'}, 
												{'name':'传感数据点数量','value':'sensor_num','width':'10%',style:'color,#3499db;',click_callback:'forwardSensorList',style_class:'pointer' }, 
												{'name':'设备触发数量','value':'trigger_num','width':'10%',style:'color,#3499db;',click_callback:'forwardTrigger',style_class:'pointer'}, 
												{'name':'操作','type':'self','value_callback':'value_function','width':'5%'}]" > 
								</div>
							</div> 
						</div>
					</div>
				</div>
			</div>
			
			<div style="display:none;padding:20px;" type-option="form_submit" id="add" 
								  config-option=" 'url':'/deviceTemplateInfo',
												  'submit':'.add-Btn',
												  'success':'sunccessReturn' ">
				<input  type-name="user_id" value="${user.id}" type="hidden"   >
				<div class="form-line">
					<span class="red">*</span>&nbsp;<span>设备类型名称：</span>
					<div class="pb-10 pt-10">
						<input placeholder="输入名称" validate="empty" type-name="name" class="input input-big clear-v" >
					</div>	
				</div>
				<div class="form-line clearfix">
					<button onclick="closeAll();" class="button border-gray ml-10 button-big float-right">取消</button>
					<button class="add-Btn button ml-20 bg-iot button-big float-right">保存</button>
				</div>
			</div>
			
			<div style="display:none;padding:20px;" type-option="form_submit" id="modify" 
										  config-option=" 'url':'/deviceTemplateInfo','method':'put',
														  'submit':'.modify-Btn',
														  'success':'sunccessReturn' ">
				<div id="detail_get" config-option=" 'url':'/deviceTemplateInfo?id=$#init-id$' ">
					<input type="hidden" type-name="id" id="init-id" >
					<div class="form-line">
						<span class="red">*</span>&nbsp;<span>设备类型名称：</span>
						<div class="pb-10 pt-10">
							<input placeholder="输入名称" validate="empty" type-name="name" class="input input-big" >
						</div>	
					</div>
					<div class="form-line clearfix">
						<button onclick="closeAll();" class="button border-gray ml-10 button-big float-right">取消</button>
						<button class="modify-Btn button ml-20 bg-iot button-big float-right">保存</button>
					</div>
				</div>
			</div>
			
		</div>
	</div>
</body>
<script type="text/javascript">
function changeScene(obj){
	$(".dashboard-menu li").removeClass("active");
	$(obj).addClass("active");
	$(".scene_id").val($(".dashboard-menu li.active").attr("sid"));
	reflash( $(".dashboard-menu li.active").attr("sid"));
}
function reflash(id){
	$("#init-table").data("params",{ scene_id: $(".scene_id").val() });
	$("#init-table").tableAdaptor();
}

function add(){
	// 判断是否增加项目，没有的话，则提示
	openWindow("新增设备类型","#add","600px");
	// 清空表单
	$("#add .clear-v").val("");		
	
}

function value_function(data,seq){
	return "<span tag='编辑' onclick='t_edit(this,"+data.id+")' class='self-icon icon-edit'></span>"+
    "<span tag='删除' onclick='t_delete(this,"+data.id+")' class='self-icon icon-bitbucket'></span>";
}

function sunccessReturn(data){
	if( data.status == status_code.OK ){
 		tip("成功");
 		setTimeout(function(){
 			closeAll();
 			$("#init-table").tableAdaptor();
 		},1000)
	}else{
		tip(data.statusMsg);
	}
}

function t_edit(obj,id){
	writeVal("init-id",id);
	openWindow("编辑设备","#modify","600px");
	manual_init_detail_get($("#detail_get"));
}

function t_delete(obj,id){
	lcomfirm('是否确定删除该设备类型，不影响老数据？',function(){ 
		commonAjax("DELETE",localUrl+"/deviceTemplateInfo?id="+id, "",function(){
			tip("删除成功");
			setTimeout(function(){
				closeAll();
				$("#init-table").tableAdaptor();
			},1000)
		});
	});
}

function forwardSensorList(obj){
	forwardUrl('/iot/template_sensor_list?id=' + $(obj).parent().attr("value") );
}
function forwardTrigger(obj){
	forwardUrl('/iot/template_trigger_list?id=' + $(obj).parent().attr("value"));
}
</script>
</html>